"""
    
    Application main class.

"""

__author__ = "Mikko Ohtamaa <mikko@redinnovation.com"
__docformat__ = "epytext"
__copyright__ = "Red Innovation Ltd."
__license__ = "BSD"

import os
import sys

from movz.client.generic.app.application import Application as GenericApplication

class Application(GenericApplication):
    """ Python for Series 60 application main class.
    
    Thread-aware logger will write log output to the memory card root.
    """

    def __init__(self):
        
        GenericApplication.__init__(self)
        
        #: Logger object, use get_logger() to access
        self.logger = None
        
        #: Applicatio main (ui) thread lock (TimeoutLock)
        self.lock = None
        
    def get_logger(self):
        return self.logger

    def is_debugging(self):
        return True
                    
    def get_splash_screen(self):
        """
        
        @return (rgb background color, absolute bitmap path) or (None, None)
        """
        return (None, None)

    
    def exit(self):
        raise NotImplementedError()
    
    def run(self):
        """ Application entry point.
        
        The subclass must override this.        
        """
                
    def init_logger(self, fname):
        from movz.client.s60.app import logger
        from movz.client.s60.thread import Signaller
        signaller = Signaller(self.lock, "Awaken by logger")
        self.logger = logger.S60LoggingManager.setup_basic_logging(signaller, fname, self.is_debugging())
        
    def init_framework(self):
        
        from movz.client.s60 import thread
        
        self.lock = thread.TimeoutLock("Main thread log for " + self.get_name())

        self.init_logger("E:\\" + self.get_name())

        
    def start(self):
        """ Call this in the application entry thread.
        
        """

        color, splash = self.get_splash_screen()
        if splash:
            import splashscreen
            splashscreen.splash(splash, color)
        
        self.init_framework()
        
        self.prepare()
        
        if splash:
            splashscreen.unsplash()
        
        self.run()